/*
 *  PMBoundingBox.h
 *  PezMonkey
 *
 *  Created by Spence DiNicolantonio on 10/29/09.
 *  Copyright 2009 Necrosoft. All rights reserved.
 *
 */


/**
 * A simple bounding box. This structure is interchangable with Chipmunk's cpBB
 * structure.
 */

#import <Foundation/Foundation.h>
#import "chipmunk.h"


#pragma mark Type Definition
typedef cpBB PMBoundingBox;


#pragma mark -
#pragma mark Static Inline Functions

/**
 * Constructs a PMBoundingBox structure with given left, bottom, right, and top
 * values.
 */
static inline PMBoundingBox PMBoundingBoxMake(const PMFloat left, 
											  const PMFloat bottom, 
											  const PMFloat right, 
											  const PMFloat top) {
	return (PMBoundingBox) cpBBNew(left, bottom, right, top);
}

/**
 * Determines whether two given bounding boxes intersect each other.
 */
static inline BOOL PMBoundingBoxIntersects(const PMBoundingBox bb1, const PMBoundingBox bb2) {
	return cpBBintersects(bb1, bb2);
}

/**
 * Determines whether one given bounding box contains another.
 */
static inline BOOL PMBoundingBoxContainsBoundingBox(const PMBoundingBox container, 
												   const PMBoundingBox other) {
	return cpBBcontainsBB(container, other);
}

/**
 * Determines whether a given bounding box contains a given point.
 */
static inline BOOL PMBoundingBoxContainsPoint(const PMBoundingBox bb, const PMVect point) {
	return cpBBcontainsVect(bb, point);
}

/**
 * Calculates the minimum bounding box that contains both given bounding boxes.
 */
static inline PMBoundingBox PMBoundingBoxMerg(const PMBoundingBox bb1, const PMBoundingBox bb2) {
	return cpBBmerge(bb1, bb2);
}

/**
 * Calculates the minimum bounding box that contains both the given bounding box
 * and the given vector.
 */
static inline PMBoundingBox PMBoundingBoxExpand(const PMBoundingBox bb, const PMVect v){
	return cpBBexpand(bb, v);
}

/**
 * Calculates the width of a given bounding box.
 */
static inline PMFloat PMBoundingBoxWidth(const PMBoundingBox bb) {
	return (bb.r - bb.l);
}

/**
 * Calculates the height of a given bounding box.
 */
static inline PMFloat PMBoundingBoxHeight(const PMBoundingBox bb) {
	return (bb.t - bb.b);
}


#pragma mark -
#pragma mark Other Functions

/**
 * Clamps a given vector to a given bounding box.
 */
static PMVect PMBoundingBoxClampVect(const PMBoundingBox bb, const PMVect v) {
	return (PMVect) cpBBClampVect(bb, v);
}

/**
 * Wraps a given vector to a given bounding box.
 */
static PMVect PMBoundingBoxWrapVect(const PMBoundingBox bb, const PMVect v) {
	return (PMVect) cpBBWrapVect(bb, v);
}